package logic

//注册
import (
	"context"
	"go-zero-demo-04/mall/user/api/internal/svc"
	"go-zero-demo-04/mall/user/api/internal/types"
	"go-zero-demo-04/mall/user/rpc/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type RegisterLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewRegisterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RegisterLogic {
	return &RegisterLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *RegisterLogic) Register(req *types.RegisterRequest) (resp *types.RegisterResponse, err error) {
	res, err := l.svcCtx.UserRpc.Register(l.ctx, &user.RegisterRequest{
		CollegeName:    req.CollegeName,
		DepartmentName: req.DepartmentName,
		ClassID:        req.ClassID,
		StudentID:      req.StudentID,
		StudentName:    req.StudentName,
		Age:            req.Age,
		Sex:            req.Sex,
		Password:       req.Password,
	})
	if err != nil {
		return nil, err
	}

	return &types.RegisterResponse{
		Result: res.Result,
	}, nil

}
